package com.epoint.BookManager.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Response;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.epoint.BookManager.domain.BookInfo;
import com.epoint.BookManager.service.BookInfoService;


@WebServlet("/BookInfoAddAction")
public class BookInfoAddAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
    BookInfoService bookInfoService = new BookInfoService();
  
    public BookInfoAddAction() {
        super();
        
    }	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String data = request.getParameter("data");
		JSONObject jsonObject = JSONObject.parseObject(data);
		BookInfo bookInfo = JSON.toJavaObject(jsonObject, BookInfo.class);
		boolean falg = bookInfoService.addBook(bookInfo);
		Map<String, String> result  = new HashMap<>();
		if (falg) {
			result.put("msg", "保存成功");
		}else {
			result.put("msg", "添加失败");
		}
		response.getWriter().print(JSONUtils.toJSONString(result));
	}
}
